﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LLFM.CAT.Model;
using LLFM.CAT.Service;
using Common;
using LLFM.CAT.Enum;

public partial class Product_ProductDetail : PageBase
{
    protected int ProductId { get { return RequestHelper.GetInt("productid", 0); } }
    protected M_Products Product { set; get; }
    protected M_ProductExtention ProductExtention { set; get; }
    protected List<M_ProductsImages> ProductImageslist { set; get; }
    protected void Page_Load(object sender, EventArgs e)
    {
        Product = ProductsService.GetProductById(ProductId);
        navuc.CurrentTagLevelOne = 2;
        navuc.CurrentTagLevelTwo = 2 * 10 + Product.SeriesId;
        InitBread();
        ProductExtention = ProductExtentionService.GetProductExtentionByProductId(ProductId);
        ProductImageslist = ProductsImagesService.GetProductImagesListByProductId(ProductId, 1);
        rptProductImageList.DataSource = ProductImageslist;
        rptProductImageList.DataBind();
    }

    protected void ProductImageListDataBound(object sender, RepeaterItemEventArgs e) 
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            M_ProductsImages productsImages = (M_ProductsImages)e.Item.DataItem;
            Literal ltlText = (Literal)e.Item.FindControl("ltlText");
            string text = "<li class='{0}'><span class='cover'></span><img src='" + productsImages.SmallImageUrl + "'></li>";
            ltlText.Text = text;
            if (e.Item.ItemIndex == ProductImageslist.Count-1)
            {
                ltlText.Text = string.Format(text, "last");
            }
        }
    }

    private void InitBread() 
    {
        Dictionary<string, string> dic = new Dictionary<string,string>();
        dic.Add("首页", "../Index.aspx");
        dic.Add("挖机产品", "../Product/SeriesDetail.aspx");
        dic.Add(Enum.GetName(typeof(SeriesEnum),Product.SeriesId), "../Product/SeriesDetail.aspx?seriesid=" + Product.SeriesId);
        dic.Add(Product.Name,"../Product/ProductDetail.aspx?productid=" + Product.Id);
        bread1.dic = dic;
    }
}